#include<iostream>
#include<cstdio>
using namespace std;
const int N = 2e4 + 10;
int p[N];
int n, m, q;
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		p[i] = i;
	}
	while (m--) {
		int a, b;
		scanf("%d%d", &a, &b);
		int pa = find(a);
		int pb = find(b);
		if (pa != pb) {
			p[pa] = pb;
		}
	}
	scanf("%d", &q);
	while (q--) {
		int a, b;
		scanf("%d%d", &a, &b);
		int pa = find(a);
		int pb = find(b);
		if (pa == pb) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	return 0;
}